package com.greet.controller.admin;

import com.greet.result.Result;
import com.greet.service.ReportService;
import com.greet.vo.OrderReportVO;
import com.greet.vo.SalesTop10ReportVO;
import com.greet.vo.TurnoverReportVO;
import com.greet.vo.UserReportVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;

@RestController
@RequestMapping("/admin/report")
@Slf4j
public class ReportController {

    @Autowired
    private ReportService reportService;

    @GetMapping("/turnoverStatistics")
    public Result<TurnoverReportVO> turnoverStatistics(
            @DateTimeFormat(pattern = "yyyy-mm-dd")LocalDate begin,
            @DateTimeFormat(pattern = "yyyy-mm-dd")LocalDate end){
        log.info("营业额数据统计");
        TurnoverReportVO reportVO = reportService.turnoverStatistics(begin, end);
        return Result.success(reportVO);
    }

    @GetMapping("/userStatistics")
    public Result<UserReportVO> userStatistics(
            @DateTimeFormat(pattern = "yyyy-mm-dd")LocalDate begin,
            @DateTimeFormat(pattern = "yyyy-mm-dd")LocalDate end){
        log.info("进行用户统计");
        UserReportVO reportVO = reportService.userStatistics(begin, end);
        return Result.success(reportVO);
    }

    @GetMapping("/ordersStatistics")
    public Result<OrderReportVO> ordersStatistics(
            @DateTimeFormat(pattern = "yyyy-mm-dd")LocalDate begin,
            @DateTimeFormat(pattern = "yyyy-mm-dd")LocalDate end){
        log.info("进行订单统计");
        OrderReportVO reportVO = reportService.ordersStatistics(begin, end);
        return Result.success(reportVO);
    }

    @GetMapping("/top10")
    public Result<SalesTop10ReportVO> top10(
            @DateTimeFormat(pattern = "yyyy-mm-dd")LocalDate begin,
            @DateTimeFormat(pattern = "yyyy-mm-dd")LocalDate end){
        log.info("进行热销前10菜品(套餐)统计");
        SalesTop10ReportVO reportVO = reportService.top10(begin, end);
        return Result.success(reportVO);
    }
}
